COPIED from:http://www.cnblogs.com/wuming/archive/2010/02/24/1672906.htmlFrom a table random 2 records, with select TOP * from Ywle ORDER by NEWID () the order by is generally sorted by a field, the return value of newid () is uniqueidentifier,
Obtain two random records FROM table A and use select top 10 * FROM ywle order by newid ()Order by is generally sorted by a certain field. The return value of newid () is uniqueidentifier. How does order by newid () randomly select records?Newid ()
Randomly fetch 2 records from a table, using select TOP * from Ywle ORDER by NEWID ()Order by is generally sorted by a field, the return value of newid () is uniqueidentifier, and the Order by NEWID () random selection record is performedNEWID ()
Obtain two random records from table A and use select top 10 * From ywle order by newid ()Order by is generally sorted by a certain field. The return value of newid () is uniqueidentifier. How does order by newid () randomly select records?Newid ()
CreateUniqueidentifierUnique value of type.Syntax
NEWID ( )Return type
UniqueidentifierExample A. Use the newid function for the variable
The following example uses newid to declareUniqueidentifierAssign values to variables of the data type. Print
Maybe you should be familiar with the ms SQL built-in function newid. Yesterday, my colleague asked me how to check the mobile phone number in LINQ. I did not think twice, do you want to use it. net's random () function to generate a selection
In daily operations, sometimes it may be that some activities to draw out the winners or select some of the list, It is often used to order by Newid () the way to do random number selection, but the possible situation needs to be matched to
The Random Functions NewID (), Rand (), newidrand in SQL server
In SQL Server, random functions include rand (), NewID (), where rand is a random number from 0 to 1, and NewID is the unique identifier of the random uniqueidentifier generated.
SELECT
Inin the SQL language, the random function newid and rand () are not used in the same way, the following will give you a sample analysis of the differences between these two random functions, for your reference, you want to understand the SQL
In SQL Server, random functions have rand (), NewID (), where Rand is randomly fetched in 0 to 1, and NewID is a random uniqueidentifier unique identifier.
SELECT * from Northwind.. Orders by NEWID ()--Random sort
SELECT Top * from Northwind..
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.